package com.fsnbigdata.web;

import com.fsnbigdata.service.api.StatisticService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by zhongcheng on 04/12/2017.
 */
@RestController
@RequestMapping( value = "/api/statistic", produces = MediaType.APPLICATION_JSON_VALUE )
@Api(tags = "Statistic", description = "统计信息" )
public class StatisticController {

    @Autowired
    StatisticService statisticService;

    @GetMapping( value = "/dataCount" )
    public Map<String, Long> dataCount() {
        return this.statisticService.countAllDatabase();
    }

    /**
     * 首页全局模糊分页查询
     */
    @GetMapping("searchAll")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", defaultValue = "0", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "size", defaultValue = "20", dataType = "int", paramType = "query")
    })
    public List findAllByKey(HttpServletRequest request, Pageable pageable){
        String key = request.getParameter( "key" );
        return statisticService.findAllByKeyWords( key,pageable );
    }

    @GetMapping("count")
    public String count(){
        return statisticService.count();
    }
}
